<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<title>快递代发</title>
<jsp:include page="../../views/layout/inc.jsp"></jsp:include>
<link rel="stylesheet" href="/css/core/easyui/easyui-rtl.css?v=201505241044"/>
<%-- <c:if test="${fn:contains(sessionInfo.resourceList, '/propertyCompanyController/editPage')}"> --%>
	<script type="text/javascript">
		$.canEdit = true;
	</script>
<%-- </c:if> --%>
<%-- <c:if test="${fn:contains(sessionInfo.resourceList, '/propertyCompanyController/delete')}"> --%>
	<script type="text/javascript">
		$.canDelete = true;
	</script>
<%-- </c:if> --%>
<script type="text/javascript">
	
	
	
	var dataGrid;
	$(function() {
		dataGrid = $('#dataGrid').datagrid({
			singleSelect : true,
			url : '/sendCourierController/dataGrid',
			fit : true,
			fitColumns : false,
			border : false,
			pagination : true,
			idField : 'id',
			pageSize : 10,
			pageList : [ 10, 20, 30, 40, 50 ],
			sortName : 'gmtCreate',
			sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : false,
			nowrap : true,
			columns : [ [  {
				field : 'outBizNum',
				title :'快递单号',
				width : 100
			},{
				field : 'name',
				title :'订单名称',
				width : 100
			},{
				field : 'companyName',
				title :'快递公司',
				width : 200
			}/* ,{
				field : 'courierType',
				title :'快递类型',
				width : 100,
				formatter:function(val,rec){ 
					if(val == 1) {
						return '普通';
					}else if(val == 2) {
						return '及时';
					}else {
						return '未知';
					}
				}
			} */,{
				field : 'srcAccountName',
				title :'发件人',
				width : 100
			},{
				field : 'srcMobile',
				title :'发件人电话',
				width : 100
			},{
				field : 'srcAreaDetail',
				title :'发件地址',
				width : 300,
				formatter:function(val,rec){ 
					return rec.srcProvinceName + rec.srcCityName + rec.srcDistrictName + val;
				}
			},{
				field : 'desAccountName',
				title :'收件人',
				width : 100
			},{
				field : 'desMobile',
				title :'收件人电话',
				width : 100
			},{
				field : 'desAreaDetail',
				title :'收件地址',
				width : 300,
				formatter:function(val,rec){ 
					return rec.desProvinceName + rec.desCityName + rec.desDistrictName + val;
				}
			},{
				field : 'amount',
				title :'快递费用（元）',
				width : 100,
				formatter:function(val,rec){ 
					if(val != null) {
						return val/100;
					}
				}
			},{
				field : 'status',
				title :'状态',
				width : 100,
				formatter:function(val,rec){ 
					if(val == 1) {
						return '待处理';
					}else if(val == 2) {
						return '<span style="color:green">已发件</span>';
					}else if(val == 3) {
						return '<span style="color:red">关闭</span>';
					}else if(val == 4) {
						return '<span style="color:#808080">删除</span>';
					}else if(val == 5) {
						return '已取件';
					}else {
						return '未知';
					}
				}
			},{
				field : 'remark',
				title :'备注',
				width : 200
			},{
				field : 'gmtCreate',
				title : '创建时间',
				width : 150,
				formatter:function(val,rec){ 
					 var unixTimestamp = new Date(val);  
                     return unixTimestamp.format("yyyy-MM-dd hh:mm:ss");  
				}
			}, {
				field : 'gmtModify',
				title : '修改时间',
				width : 150,
				formatter:function(val,rec){ 
					if(val == "" || val == null) {
						return "";
					}
					 var unixTimestamp = new Date(val);  
                    return unixTimestamp.format("yyyy-MM-dd hh:mm:ss");  
				}
			} ] ],
			frozenColumns : [[{
				field : 'action',
				title : '操作',
				width : 50,
				formatter : function(value, row, index) {
					var str = '';
					if ($.canEdit) {
						str += $.formatString('<img onclick="editFun(\'{0}\');" src="{1}" title="修改"/>', row.id, '/images/extjs_icons/pencil.png');
					}
					str += '&nbsp;';
					/* if ($.canDelete) {
						str += $.formatString('<img onclick="deleteFun(\'{0}\');" src="{1}" title="删除"/>', row.id, '/images/extjs_icons/cancel.png');
					}  */
					return str;
				}
			}]],
			toolbar : '#toolbar',
			onLoadSuccess : function() {
				$('#searchForm table').show();
				parent.$.messager.progress('close');

				$(this).datagrid('tooltip');
			},
			onRowContextMenu : function(e, rowIndex, rowData) {
				e.preventDefault();
				$(this).datagrid('unselectAll').datagrid('uncheckAll');
				$(this).datagrid('selectRow', rowIndex);
				$('#menu').menu('show', {
					left : e.pageX,
					top : e.pageY
				});
			},
			onDblClickRow : function(rowIndex, rowData){
				editFun(rowData.id);
			}
		});
		
		
		$.ajax({
			type:'post',
			url:'/companyExpressController/getCombobox',
			success:function(result) {
				$('#companyId').combobox({
					data : result,
				    panelHeight:'auto'
				});
				sessionStorage.setItem("comboboxExpress", JSON.stringify(result));
			},
			dataType:'json'
		});
		
		
		$('#status').combobox({
			data : [{"value":1,"text":"待处理"},
			        {"value":2,"text":"已发件"},
			        {"value":3,"text":"关闭"},
			        {"value":4,"text":"删除"},
			        {"value":5,"text":"已取件"}],
		    panelHeight:'auto'
		});
		
		<c:if test="${not empty param}">
		dataGrid.datagrid('load', {"status":"${param.status}"});
		</c:if>
		
		
		document.onkeydown = function(e) {
			var theEvent = window.event || e;
			var code = theEvent.keyCode || theEvent.which;
			if (code == 13) {
				searchFun();
			}
		}
	});

	function deleteFun(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = dataGrid.datagrid('getSelections');
			id = rows[0].id;
		} else {//点击操作里面的删除图标会触发这个
			dataGrid.datagrid('unselectAll').datagrid('uncheckAll');
		}
		parent.$.messager.confirm('询问', '您是否要删除当前快递点？', function(b) {
			if (b) {
				parent.$.messager.progress({
					title : '提示',
					text : '数据处理中，请稍后....'
				});
				$.post('/sendCourierController/delete', {
					id : id
				}, function(result) {
					parent.$.messager.alert('提示', result.msg, 'info');
					if (result.success) {
						dataGrid.datagrid('reload');
					}
					parent.$.messager.progress('close');
				}, 'JSON');
			}
		});
	}

	function editFun(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = dataGrid.datagrid('getSelections');
			id = rows[0].id;
		} else {//点击操作里面的发布图标会触发这个
			dataGrid.datagrid('unselectAll').datagrid('uncheckAll');
		}
		parent.$.modalDialog({
			title : '修改代发快递单',
			width : 600,
			height : 580,
			href : '/sendCourierController/editPage?id=' + id,
			buttons : [ {
				text : '确认修改',
				handler : function() {
					parent.$.modalDialog.openner_dataGrid = dataGrid;//因为修改成功之后，需要刷新这个treeGrid，所以先预定义好
					var f = parent.$.modalDialog.handler.find('#form');
					f.submit();
				}
			} ]
		});
	}

	function addFun() {
		parent.$.modalDialog({
			title : '新增代发快递单',
			width : 600,
			height : 550,
			href : '/sendCourierController/addPage',
			buttons : [ {
				text : '确认新增',
				handler : function() {
					parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
					var f = parent.$.modalDialog.handler.find('#form');
					f.submit();
				}
			} ]
		});
	}

	function searchFun() {
		dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
	}
	function cleanFun() {
		$('#searchForm input').val('');
		dataGrid.datagrid('load', {});
	}

	function downloadExcel() {

		var url = '/sendCourierController/downloadExcel';
		var queryData = $.serializeObject($('#searchForm'));
		var index = 0;
		for ( var name in queryData) {
			if (index == 0) {
				url += "?";
			} else {
				url += "&";
			}
			url += name + "=" + queryData[name];
			index++;
		}
		window.open(url);

	}

</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',title:'查询条件',border:false" style="height: 170px; overflow: hidden;">
			<form id="searchForm">
				<table class="table table-hover table-condensed" style="display: none;">
					<tr>
						<th>快递点</th>
						<td><input name="companyId" id="companyId" /></td>
					</tr>
					<tr>
						<th>发件人手机号</th>
						<td><input name="srcMobile" type="text" class="easyui-validatebox mobile" data-options="validType:'isPhoneNumber'"/></td>
					</tr>
					<tr>
						<th>状态</th>
						<td><input name="status" id="status" /></td>
					</tr>
					<tr>
						<th>新增时间</th>
						<td><input name="startGmtCreate" id="startGmtCreate" placeholder="点击选择时间" class="Wdate" style="width:150px" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'endGmtCreate\') || \'%y-%M-%d\'}'})"/>
							至<input name="endGmtCreate" id="endGmtCreate" placeholder="点击选择时间" class="Wdate" style="width:150px" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'startGmtCreate\') || \'%y-%M-%d\'}'})"/></td>
					</tr>
					<tr>
						<th>修改时间</th>
						<td><input name="startGmtModify" id="startGmtModify" placeholder="点击选择时间" class="Wdate" style="width:150px" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'endGmtModify\') || \'%y-%M-%d\'}'})"/>
							至<input name="endGmtModify" id="endGmtModify" placeholder="点击选择时间" class="Wdate" style="width:150px" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'startGmtModify\') || \'%y-%M-%d\'}'})"/></td>
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',border:false">
			<table id="dataGrid"></table>
		</div>
	</div>
	<div id="toolbar" style="display: none;">
<%-- 		<c:if test="${fn:contains(sessionInfo.resourceList, '/propertyCompanyController/addPage')}"> --%>
			<a onclick="addFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">新增</a>
<%-- 		</c:if> --%>
		<a onclick="downloadExcel();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-redo'">导出</a>
		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="searchFun();">提交查询</a>
		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true" onclick="cleanFun();">重置查询</a>
	</div>

	<div id="menu" class="easyui-menu" style="width: 120px; display: none;">
<%-- 		<c:if test="${fn:contains(sessionInfo.resourceList, '/propertyCompanyController/editPage')}"> --%>
			<div onclick="editFun();" data-options="iconCls:'icon-edit'">修改</div>
<%-- 		</c:if> --%>
<%-- 		<c:if test="${fn:contains(sessionInfo.resourceList, '/propertyCompanyController/addPage')}"> --%>
			<!-- <div onclick="addFun();" data-options="iconCls:'icon-add'">新增</div> -->
<%-- 		</c:if> --%>
<%-- 		<c:if test="${fn:contains(sessionInfo.resourceList, '/propertyCompanyController/delete')}"> --%>
			<!-- <div onclick="deleteFun();" data-options="iconCls:'icon-remove'">删除</div> -->
<%-- 		</c:if> --%>
	</div>
</body>
</html>